<?php echo $this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>EMMS</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" href="/js/dojo/1.7.2/dijit/themes/claro/claro.css"/>
        <link rel="stylesheet" type="text/css" href="/js/dojo/1.7.2/dojox/grid/resources/Grid.css"/>
        <link rel="stylesheet" type="text/css" href="/css/claroGrid.css"/>
        <link rel="stylesheet" type="text/css" href="/css/style.css"/>
        <link rel="stylesheet" type="text/css" href="/css/grid.css"/>
        <script type="text/javascript" src="/js/dojo/1.7.2/dojo/dojo.js" djConfig="parseOnLoad: true"></script>
        <script type="text/javascript" src="/js/dojo/1.7.2/dijit/dijit.js"></script>
        <script type="text/javascript">
            dojo.require("dojo.parser");
            dojo.require("dojox.grid.DataGrid");
            dojo.require("dijit.form.Button");
            dojo.require("dijit.form.TextBox");
            dojo.require("dojo.data.ItemFileReadStore");
            dojo.require("dijit.layout.BorderContainer");
            dojo.require("dijit.Toolbar");
            function minimize() { 
                document.getElementById("theGridContainer").style.visibility='hidden'; 
                parent.document.getElementById('wrapper').rows = '40,*,32'; 
            }
            function restore() { 
                parent.document.getElementById('wrapper').rows = '40,*,300';
                document.getElementById("theGridContainer").style.visibility='visible'; 
            }
            function maximize() { 
                parent.document.getElementById('wrapper').rows = '0,0,*';
                document.getElementById("theGridContainer").style.visibility='visible'; 
            }
        </script>
    </head>
    <body class=" claro ">
        <div dojoType="dijit.layout.BorderContainer" id="theBorderContainer">            
            <!-- The grid container -->
            <div id="theGridContainer">
            <?php if(is_array($this->data)) : ?>
                <?php //echo $this->layout()->content ?>
                <script type="text/javascript">
                <?php if(isset(Zend_Auth::getInstance()->getIdentity()->resources[$this->meta['onClick']])) : ?>
                function click(e)
                { 
                    var item = theGrid.getItem(e.rowIndex);
                    var url = <?php echo $this->partial('partials/gridClick.phtml', (object) array('meta' => $this->meta, 'identifier' => $this->identifier)); ?>
                    parent.main.location.href = url;
                }
                <?php endif ?>        
                /* var theDataStore = new dojo.data.ItemFileReadStore({data: <?php printf("{'identifier':'%s','label':'Item','items':%s}",$this->identifier,json_encode($this->data)) ?>}); */
                var theDataStore = new dojo.data.ItemFileReadStore({data: <?php printf("{'identifier':'','label':'Item','items':%s}",json_encode($this->data)) ?>});
                </script>
                <!-- Grid -->
                <table dojoType="dojox.grid.DataGrid" id="theGrid" jsId="theGrid" store="theDataStore" queryOptions="{ignoreCase:true}" rowSelector="0px" columnReordering="false" autoHeight="true" autoWidth="true" rowsPerPage=1>
                    <thead>
                        <tr>
                            <?php foreach($this->meta['headers'] as $col) : ?>
                            <th noresize="true" width="<?php echo $col[1] ?>" field="<?php echo $col[0] ?>"><?php echo $col[2] ?></th>
                            <?php endforeach ?>
                        </tr>
                    </thead>
                    <script type="dojo/method" event="onClick" args="e"> 
                        click(e); 
                    </script>
                </table>
                <!--/ Grid -->
            <?php endif ?>
            </div>
            <!-- The grid nav/info strip -->
            <div id="nav">
                <span dojoType="dijit.Toolbar" id="paginator-navbar">
                    <span  class="label">
                        <?php echo $this->meta['title'] ?> 
                        <?php foreach($this->meta['titleMods'] as $titleMod) : ?> 
                            <?php if(isset($this->request['mod'][$titleMod])) echo '. ' . $this->translate($this->request['mod'][$titleMod]) ?>
                        <?php endforeach; ?>
                    </span>
                    <?php echo $this->paginationControl($this->paginator,'Sliding','partials/paginator.phtml',$this->request); ?>
                    <?php if($this->paginator->getTotalItemCount() > 0): ?>
                        <span class="nav-label"><?php echo $this->translate('Search') ?>:</span>
                        <span id="theFilter" class="nav-val <?php echo isset($this->meta['filter']) ? '' : 'hidden' ?>">
                            <form method="post" style="display: inline">
                                <input dojoType="dijit.form.TextBox" jsId="jumpTo" type="text" id="filter" name="filter" style="width:140px"  value="<?php echo $this->filter ?>" onClick="this.value = '';"/>
                            </form>
                        </span>
                        <span class="nav-label"></span>
                        <span class="nav-val"><a href="<?php echo $this->request['baseUrl'] ?>"><?php echo $this->translate('Reload') ?></a></span>
                        <span class="nav-val"><a href="<?php echo $this->request['baseUrl'] ?>/format/xml"><?php echo $this->translate('Export') ?></a></span>
                    <?php endif; ?>
                </span>
            </div>
            <div style="height: 30px; position: absolute; bottom: 0px; right: 40px;">
                <span dojoType="dijit.Toolbar" style="background: none transparent; margin:0px">
                    <div dojoType="dijit.form.Button" showLabel="false" iconClass="button minimize" onClick="minimize();"><?php echo $this->translate("Minimize grid") ?></div>
                    <div dojoType="dijit.form.Button" showLabel="false" iconClass="button restore" onClick="restore();"><?php echo $this->translate("Restore grid") ?></div>
                    <div dojoType="dijit.form.Button" showLabel="false" iconClass="button maximize" onClick="maximize();"><?php echo $this->translate("Maximize grid") ?></div>
                </span>
            </div>
        </div>
    </body>
</html>
